<?php 
session_start();
if ($_SESSION['auth'] != true && $_SESSION['rule'] != "ADMIN") {
	die('Not log in');
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Admin</title>
<link href="itelement.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="script/jquery.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready (
	function () {
		$('#addPublisher').click(
			function(){
				var err = publisherReq();
				if(err != ''){
					$('#status').show('fast');
					$('#status').html(err);
					return;
				}
				//add publisher
				var serialize = $('form').serializeArray( );
				$('#status').show('fast');
				$('#status').text('Wait server...');
				$.post("admin_operation.php?action=add_publisher", serialize,
				  function(data){
					$('#status').text(data);
				  });
			}
		);
	}
);
function publisherReq(){
	var br = '<br />';
	var err = '';
	if($('#username').val()==''){
		err += 'o  Username field requires'+br;
	}
	if($('#password').val()==''){
		err += 'o  Password field requires'+br;
	}
	if($('#fname').val()==''){
		err += 'o  Firstname field requires'+br;
	}
	if($('#lname').val()==''){
		err += 'o  Lastname field requires'+br;
	}
	if($('#company').val()==''){
		err += 'o  Company field requires'+br;
	}
	if(err != '')err = err.substring(0,err.length-br.length);
	return err;
}
</script>
</head>
<body>
<form action="admin_operation.php?action=add_publisher" method="post" name="form">
	  	  <div class="viewer-head">
		  	<div class="viewer-head-left">Add Publisher</div>
			<!--<div class="viewer-head-right"><input type="button" value="reset"></div>-->
		  </div>
		  <div class="input">
			Username
			  *
			  <div>
			  <input style="width:100%" id="username" name="username" type="text">
			</div>
		  </div>
		  <div class="input">
			Password
			  *
			  <div>
			  <input style="width:100%" id="password" name="password" type="password">
			</div>
		  </div>
		  <div class="input">
			Firstname
			  *
			  <div>
			  <input style="width:100%" id="fname" name="fname" type="text">
			</div>
		  </div>
		  <div class="input">
			Lastname
			  *
			  <div>
			  <input style="width:100%" id="lname" name="lname" type="text">
			</div>
		  </div>
		  <div class="input">
			Company
			  *
			  <div>
			  <input style="width:100%" id="company" name="company" type="text">
			</div>
		  </div>
		  <div class="input">
			Available Channel
			  <div style="height:100px;overflow:auto">
			  	<table>
			<?php
			include("includes/adminController.php");
			
			$channels = getAllChannel();
			if(!empty($channels))
			{
				foreach($channels as $c)
				{
			?>
			<tr><td><input type="checkbox" id="chIdArray[]" name="chIdArray[]" value="<?php echo $c['id']; ?>"></td><td class="list"><?php echo $c['title'];?></td></tr>
			<?php
				}
			}
			?>
				</table>
			</div>
		  </div>
		  <div id="status"></div>
		  <input type="button" value="&nbsp;&nbsp;add&nbsp;&nbsp;" id="addPublisher">
</form>
</body>
</html>